<?php

namespace App\Repositories;

use App\Admin\Question;

class QuestionRepositories
{
    public function save($request)
    {
        return Question::create($this->editdata($request));
    }

    public function edit($question)
    {
        $question['select'] = explode('.##XD', $question['select']);
        if ($question['type'] == 2) {
            $question['answer'] = str_split($question['answer']);
        }
        return $question;
    }

    public function editdata($request)
    {
        $data = $request->except('_token','top_subject');
        $data['selectnumber'] = count($data['select']);
        $data['select'] = implode('.##XD', $data['select']);
        if ($data['type'] == 2) {
            $data['answer'] = implode($data['answer']);
        }
        if ($data['type'] == 3) {
            $data['select'] = '';
            $data['selectnumber'] = 0;
        }
        return $data;
    }


}
